package com.penghk.springbootdemo.Repository;

import com.penghk.springbootdemo.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface UserRepository extends JpaRepository<User, Long> {

    //这就是Spring-data-jpa的一大特性：通过解析方法名创建查询。
    User findByName(String name);

    User findByNameAndAge(String name, Integer age);

    //编写JPQL语句
    @Query("from User u where u.name=:name")
    User findUser(@Param("name") String name);
}
